package com.uzai.console.web.dy;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.dy.dyorder.*;
import com.uzai.console.dto.jd.jdorder.JdOrderIdDto;
import com.uzai.console.dto.user.UserQuery;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.DyTokenMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.device.DeviceTypeService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.wechatprivate.DeviceWechatInfoService;
import com.uzai.console.service.dy.DyOrderService;
import com.uzai.console.service.order.OrderReStatusService;
import com.uzai.console.service.order.OrderSourceService;
import com.uzai.console.service.order.OrderStatusService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.user.UserInfoVo;
import com.uzai.console.vo.dy.dyorder.DyOrderInfoVo;
import com.uzai.console.vo.dy.dyorder.DyOrderReportVo;
import com.uzai.console.vo.order.OrderReStatusVo;
import com.uzai.console.vo.order.OrderSourceVo;
import com.uzai.console.vo.order.OrderStatusVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 抖音订单
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "抖音订单",tags = "抖音|抖音订单")
@ApiSort(10)
@RestController
public class DyOrderController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(DyOrderController.class);

    @Autowired
    private DyOrderService dyOrderService;
    @Autowired
    private OrderStatusService orderStatusService;
    @Autowired
    private OrderReStatusService orderReStatusService;
    @Autowired
    private OrderSourceService orderSourceService;
    @Autowired
    private DyTokenMapper dyTokenMapper;
    @Autowired
    private DeviceWechatInfoService deviceWechatInfoService;
    @Autowired
    private UserService userService;
    @Autowired
    private DeviceTypeService deviceTypeService;
    @Autowired
    private DeviceService deviceService;


    @ApiOperation(value = "查询抖音订单列表", notes = "查询抖音订单列表", response = DyOrderInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/dyOrder/findDyOrderList")
    public Object findDyOrderList(@RequestBody DyOrderQuery dyOrderQuery){
        return dyOrderService.findDyOrderList(dyOrderQuery);
    }

    @ApiOperation(value = "查询抖音订单详情", notes = "查询抖音订单详情", response = DyOrderInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/dyOrder/findDyOrderInfo")
    public Object findDyOrderInfo(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.findDyOrderInfo(dyOrderIdDto);
    }

    @ApiOperation(value = "查询抖音订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", notes = "查询抖音订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", response = DyOrderReportVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/dyOrder/findDyOrderReport")
    public Object findDyOrderReport(@RequestBody DyOrderQuery dyOrderQuery){
        return dyOrderService.findDyOrderReport(dyOrderQuery);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "订单删除", notes = "订单删除")
    @ApiOperationSupport(order = 4)
    @PostMapping("/dyOrder/delDyOrder")
    public Object delDyOrder(@RequestBody DyOrderDelDto dyOrderDelDto){
        return dyOrderService.delDyOrder(dyOrderDelDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "确认收货", notes = "确认收货")
    @ApiOperationSupport(order = 5)
    @PostMapping("/dyOrder/confirmReceive")
    public Object confirmReceive(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.confirmReceive(dyOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "手动维权", notes = "手动维权")
    @ApiOperationSupport(order = 6)
    @PostMapping("/dyOrder/confirmRefund")
    public Object confirmRefund(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.confirmRefund(dyOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "订单冻结", notes = "订单冻结")
    @ApiOperationSupport(order = 7)
    @PostMapping("/dyOrder/confirmFrozen")
    public Object confirmFrozen(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.confirmFrozen(dyOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "订单解冻", notes = "订单解冻")
    @ApiOperationSupport(order = 8)
    @PostMapping("/dyOrder/confirmThaw")
    public Object confirmThaw(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.confirmThaw(dyOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "解绑用户", notes = "解绑用户")
    @ApiOperationSupport(order = 9)
    @PostMapping("/dyOrder/unbindUser")
    public Object unBindUser(@RequestBody DyOrderUnbindUserDto dyOrderUnbindUserDto){
        return dyOrderService.unbindUser(dyOrderUnbindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "绑定用户", notes = "绑定用户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/dyOrder/bindUser")
    public Object bindUser(@RequestBody DyOrderBindUserDto dyOrderBindUserDto){
        return dyOrderService.bindUser(dyOrderBindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改解冻时间", notes = "修改解冻时间")
    @ApiOperationSupport(order = 11)
    @PostMapping("/dyOrder/updateThawTime")
    public Object updateThawTime(@RequestBody DyOrderThawTimeDto dyOrderThawTimeDto){
        return dyOrderService.updateThawTime(dyOrderThawTimeDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "手动下载抖音订单", notes = "手动下载抖音订单")
    @ApiOperationSupport(order = 13)
    @PostMapping("/dyOrder/downloadOrder")
    public Object downloadOrder(@RequestBody DyOrderDownLoadDto dyOrderDownLoadDto){
        dyOrderService.downloadOrder(dyOrderDownLoadDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "订单刷新", notes = "订单刷新")
    @ApiOperationSupport(order = 14)
    @PostMapping("/dyOrder/refreshOrder")
    public Object refreshOrder(@RequestBody DyOrderIdDto dyOrderIdDto){
        dyOrderService.refreshOrder(dyOrderIdDto);
        return true;
    }

    @ApiOperation(value = "查询抖音订单状态列表", notes = "查询抖音订单状态列表", response = OrderStatusVo.class)
    @ApiOperationSupport(order = 17)
    @PostMapping("/dyOrder/getOrderStatusList")
    public Object getOrderStatusList() {
        return orderStatusService.findDyOrderStatusList();
    }

    @ApiOperation(value = "查询抖音订单平台状态列表", notes = "查询抖音订单平台状态列表", response = OrderStatusVo.class)
    @ApiOperationSupport(order = 17)
    @PostMapping("/dyOrder/getOrderPlatformStatusList")
    public Object getOrderPlatformStatusList() {
        return orderStatusService.getDyOrderPlatformStatusList();
    }

    @ApiOperation(value = "查询抖音订单返利状态列表", notes = "查询抖音订单返利状态列表", response = OrderReStatusVo.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/dyOrder/getOrderReStatusList")
    public Object getOrderReStatusList() {
        return orderReStatusService.findOrderReStatusList();
    }

    @ApiOperation(value = "查询抖音订单来源列表", notes = "查询抖音订单订单来源列表", response = OrderSourceVo.class)
    @ApiOperationSupport(order = 19)
    @PostMapping("/dyOrder/getOrderSourceList")
    public Object getOrderSourceList() {
        return orderSourceService.findOrderSourceList();
    }

    @ApiOperation(value = "查询机器人下拉列表", notes = "查询机器人下拉列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 20)
    @PostMapping("/dyOrder/findDeviceWechatInfoSelectList")
    public Object findDeviceWechatInfoSelectList() {
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @ApiOperation(value = "分页查询会员信息列表", notes = "分页查询会员信息列表", response = UserInfoVo.class)
    @ApiOperationSupport(order = 22)
    @PostMapping("/dyOrder/findUserPage")
    public Object findUserPage(@RequestBody UserQuery userQuery) {
        return userService.findUserPage(userQuery);
    }

    @ApiOperation(value = "查询设备类型下拉列表", notes = "查询设备类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 23)
    @PostMapping("/dyOrder/findDeiviceTypeListSelect")
    public Object findDeiviceTypeListSelect() {
        return deviceTypeService.findDeviceTypeListSelect();
    }

    @ApiOperation(value = "查询所有未绑定用户订单", notes = "查询所有未绑定用户订单", response = DyOrderInfoVo.class)
    @ApiOperationSupport(order = 24)
    @PostMapping("/dyOrder/findUnbindUserList")
    public Object findUnbindUserList(@RequestBody DyOrderUnbindDtoQuery dyOrderUnbindDtoQuery){
        return dyOrderService.findUnbindUserList(dyOrderUnbindDtoQuery);
    }

    @ApiOperation(value = "查询所有未绑定用户统计信息(总收入、买家总金额、总利润）", notes = "查询所有未绑定用户订单统计信息(总收入、买家总金额、总利润）", response = DyOrderReportVo.class)
    @ApiOperationSupport(order = 25)
    @PostMapping("/dyOrder/findUnbindUserReport")
    public Object findUnbindUserReport(@RequestBody DyOrderUnbindDtoQuery dyOrderUnbindDtoQuery){
        return dyOrderService.findUnbindUserReport(dyOrderUnbindDtoQuery);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除所有未绑定用户订单", notes = "删除所有未绑定用户订单", response = Boolean.class)
    @ApiOperationSupport(order = 26)
    @PostMapping("/dyOrder/deleteUnbindUserList")
    public Object deleteUnbindUserList(@RequestBody DyOrderDeleteUnbindDto dyOrderDeleteUnbindDto){
        return dyOrderService.deleteUnbindUserList(dyOrderDeleteUnbindDto);
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "更新7天前未收货订单", notes = "更新7天前未收货订单", response = Boolean.class)
    @ApiOperationSupport(order = 27)
    @PostMapping("/dyOrder/updateDyOrderUnReceived")
    public Object updateDyOrderUnReceived(){
        dyOrderService.updateDyOrderUnReceivedList(getLoginInfo().getMerId());
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DyOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "追回返利", notes = "追回返利")
    @ApiOperationSupport(order = 28)
    @PostMapping("/dyOrder/rebateRefound")
    public Object rebateRefound(@RequestBody DyOrderIdDto dyOrderIdDto){
        return dyOrderService.rebateRefound(dyOrderIdDto);
    }
}
